1. Start with pixel clusters from FlowSOM (Gaussian blur sigma=2).
  2. For each point, for each pixel, look at all neighboring pixels with a radius of 2, i.e. 5x5 kernel around the center pixel. Count the number of each cluster type, then divide by total number of pixels in kernel to get the frequency of each pixel cluster in the kernel (total number of pixels is not always 24 because of edges and empty pixels that didn’t get an assignment).
  3. For each pair of clusters i and j, randomly sample the number of pixels to total number of pixels in the smaller cluster. Calculate the enrichment of cluster j near cluster i divided by the enrichment of cluster i near itself.
  4. Average across all points.

Pixel clusters x marker

Breakdown of FlowSOM clusters

## 
##       1       2       3       4       5       6       7       8       9      10 
##   18139   37490    4120   22889   22499    4255   50174   10308   18780    3738 
##      11      12      13      14      15      16      17      18      19      20 
##   44483   33009   56265   39160   60519   25506   90123   34074    3193   27648 
##      21      22      23      24      25      26      27      28      29      30 
##   18393   60321   89526   95429   61008  177108  166256    6195   39653    2909 
##      31      32      33      34      35      36      37      38      39      40 
##    8090   45685   20763   98339  132159   22182   54429   17178   79123   22338 
##      41      42      43      44      45      46      47      48      49      50 
##   27248   53528   95038  140246  216850  136414  205682  393130   52612  237841 
##      51      52      53      54      55      56      57      58      59      60 
##   18700  100084   78248  155889  236098  360600  525779  163233  344001 2456314 
##      61      62      63      64      65      66      67      68      69      70 
##   15501   16856   35281  108048  145752  237147 1121175   17734  444896  194666 
##      71      72      73      74      75      76      77      78      79      80 
##   32303   17642   52553   36215   94348  220753  621535  137140   59561   62016 
##      81      82      83      84      85      86      87      88      89      90 
##   35059   11674   25856   74795  157503  268920   57016   47355   20280    5556 
##      91      92      93      94      95      96      97      98      99     100 
##    5674    5183   11985   23110   95948  130842    1800    2050   41978    1051

All points

Plot with range 0-1

## [1] "Ratios that are greater than 1"
## [1] "c10, clust_9: 1.05018453156039"
## [1] "c6, clust_16: 1.1874202345107"
## [1] "c10, clust_20: 3.83054252118667"
## [1] "c28, clust_49: 1.34008448324584"
## [1] "c74, clust_75: 1.71945107376302"
## [1] "c73, clust_84: 2.25683052760395"
## [1] "c62, clust_91: 1.0241298463462"
## [1] "c74, clust_95: 1.0475074912756"

Plot with range 0-0.5

Plot with range 0-95th percentile

Histogram of scores

All points, zscore

Each point separately